/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Metodos;

import Atributos.ProfessorDias;
import BD.CriaConexao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Andre
 */
public class ProfessorDiasMet {
    
    
    
    private Connection conexao;
        public ProfessorDiasMet(){
        try{
            this.conexao=(Connection) CriaConexao.getConexao();
        } catch (SQLException ex) {
            Logger.getLogger(CursoMet.class.getName()).log(Level.SEVERE, null, ex);
        }
        }

public void Adicionar(ProfessorDias pd) throws SQLException{
   
    try{
        String sql="insert into prof_dia_aula(id_prof_pda, id_dia_pda, id_aula_pda)"+" values(?,?,?)";
            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql)) {
                consulta.setInt(1, pd.getId_prof());
                consulta.setInt(2, pd.getId_dias());
                consulta.setInt(3, pd.getId_aula());
                consulta.execute();
            }
        }catch (SQLException ex){
            Logger.getLogger(ProfessorDiasMet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
public void Adicionar2(ProfessorDias pd) throws SQLException{
   
    try{
        String sql="insert into prof_dia_aula3(id_prof_pda3, id_dia_pda3, id_aula_pda3)"+" values(?,?,?)";
            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql)) {
                consulta.setInt(1, pd.getId_prof());
                consulta.setInt(2, pd.getId_dias());
                consulta.setInt(3, pd.getId_aula());
                consulta.execute();
            }
        }catch (SQLException ex){
            Logger.getLogger(ProfessorDiasMet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<ProfessorDias> BuscaProfDias(int id) throws SQLException {
         String sql = "select * from prof_dia_aula where id_prof_pda = ? order by id_dia_pda,id_aula_pda";
        List<ProfessorDias> minhaLista;
        try (PreparedStatement stmt = (PreparedStatement) conexao.prepareStatement(sql)) {
            stmt.setInt(1, id);
            try (ResultSet rs = stmt.executeQuery()) {
                minhaLista = new ArrayList<>();
                while (rs.next()) {
                    ProfessorDias a1 = new ProfessorDias();
                    a1.setId_prof(rs.getInt("id_prof_pda"));
                    a1.setId_dias(rs.getInt("id_dia_pda"));
                    a1.setId_aula(rs.getInt("id_aula_pda"));
                    minhaLista.add(a1);
                }
            }
        }
        return minhaLista;
    }

    public void Deleta(int a) {
         String sql_g = "delete from prof_dia_aula where id_prof_pda=?";
        
        
        PreparedStatement consulta_g;
        try {
            consulta_g = (PreparedStatement) conexao.prepareStatement(sql_g);
            consulta_g.setInt(1, a);
        
        consulta_g.execute();
        consulta_g.close();
        } catch (SQLException ex) {
            Logger.getLogger(ProfessorDiasMet.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }

    public void adiciona(ProfessorDias pd) {
         try{
        String sql="insert into prof_dia_aula(id_prof_pda, id_dia_pda, id_aula_pda)"+" values(?,?,?)";
            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql)) {
                consulta.setInt(1, pd.getId_prof());
                consulta.setInt(2, pd.getId_dias());
                consulta.setInt(3, pd.getId_aula());
                consulta.execute();
            }
        }catch (SQLException ex){
            Logger.getLogger(CursoMet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }





}
